from Products.KnowledgeEngine.KERL.Tokens.Token import Token

class BooleanToken(Token):
    
    def __init__(self, object, namespace={}):
        if type(object) is not bool:
            raise "Creating BooleanToken with non-bool value %s" % `object`
        
        Token.__init__( self, object, namespace )
    
    def toEnglish(self):
        """ Compiles this token into english """
        
        return self.object

    def toSQL(self):
        """ Compiles this token into SQL """
        
        return self.object and "1" or "0"

    def toJavascript(self):
        
        return self.getObject() and '"true"' or '"false"'

    def toKERL(self):
        return "'" + self.getObject() + "'"

    def __str__(self):
        return str(self.getObject())